class DataType < ActiveRecord::Base
	belongs_to :sup,	:class_name => 'DataType', :counter_cache => :subs_count
	has_many :subs, :class_name => 'DataType', :foreign_key => :sup_id


	def self.get_groups
		["社会管理","社会公开","公安管控","技侦侦控"]
	end

	def self.get_count grp
		DataType.where(:group_name=>grp).count
	end

	after_create do |dt|
		note = Note.new(:ip => "127.0.0.1", :user_id => User.first.id,:controller=>"data_types")
		note.target_id = dt.id
		note.target_name = dt.name
		note.action = "create"
		note.save
	end

	after_update do |dt|
		note = Note.new(:ip => "127.0.0.1", :user_id => User.first.id,:controller=>"data_types")
		note.target_id = dt.id
		note.target_name = dt.name
		note.action = "update"
		note.save
	end

	before_destroy do |dt|
		user = User.first
		if user 
			note = Note.new(:ip => "127.0.0.1", :user_id => User.first.id,:controller=>"data_types")
			note.target_id = dt.id
			note.target_name = dt.name
			note.action = "destroy"
			note.save
		end
	end


end
